var t = getApp(), e = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ e ],
    data: {
        active: 0,
        positongStatus: 0,
        showArea: !1,
        showPopover: !1,
        activeActions: "地址",
        actions: [ {
            text: "地址",
            value: 1
        }, {
            text: "自提点",
            value: 2
        } ],
        latitude: 0,
        longitude: 0,
        plugin_name: "",
        activeID: 0,
        activeDeliver: {},
        list: [],
        kwd: "",
        search_address: "",
        city: "",
        activeActionsVaule: 1,
        isLoadMore: !0,
        page: 1,
        total_page: 0
    },
    onLoad: function(e) {
        var a = this;
        this._getLocation(function(e, i) {
            var o = i.lat, s = i.lng;
            a.setData({
                longitude: s,
                latitude: o,
                city: t._isTextEmpty(e.address_component.city) ? e.address_component.province : e.address_component.city,
                positongStatus: 1
            }), a.getNowPackageDeliver(), a.getList();
        });
    },
    getNowPackageDeliver: function() {
        var e = this, a = {
            lng: this.data.longitude || "",
            lat: this.data.latitude || ""
        }, i = null;
        try {
            i = wx.getStorageSync("deliverId");
        } catch (t) {}
        i && (a.deliver_id = i);
        var o = t.getNetAddresss("plugin.package-deliver.frontend.decorate-deliver.getNowPackageDeliver");
        t._postNetWork({
            url: o,
            data: a,
            success: function(t) {
                var a = t.data;
                1 == a.result ? e.setData({
                    activeDeliver: a.data
                }) : wx.showToast({
                    title: a.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getList: function() {
        var e = this, a = {
            lng: this.data.longitude,
            lat: this.data.latitude,
            city_name: this.data.city,
            kwd: this.data.kwd,
            search_address: this.data.search_address
        }, i = t.getNetAddresss("plugin.package-deliver.frontend.decorate-deliver.getList");
        t._postNetWork({
            url: i,
            data: a,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (e.setData({
                    list: a.data.list.data,
                    plugin_name: a.data.plugin_name,
                    "actions[1].text": a.data.plugin_name,
                    total_page: a.data.list.last_page
                }), wx.setNavigationBarTitle({
                    title: "选择" + a.data.plugin_name
                })) : wx.showToast({
                    title: a.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    chooseDeliver: function(e) {
        var a = t.getNetAddresss("plugin.package-deliver.frontend.decorate-deliver.choosePackageDeliver");
        t._postNetWork({
            url: a,
            data: {
                deliver_id: e
            },
            success: function(t) {
                var a = t.data;
                1 == a.result ? (wx.setStorageSync("deliverId", e.detail), wx.showModal({
                    title: "提示",
                    showCancel: !1,
                    content: a.msg,
                    success: function(t) {
                        try {
                            wx.navigateBack({
                                delta: 1,
                                fail: function() {
                                    wx.reLaunch({
                                        url: "/packageG/index/index"
                                    });
                                }
                            });
                        } catch (t) {
                            console.log(t);
                        }
                    }
                })) : wx.showToast({
                    title: a.msg,
                    duration: 1e3,
                    icon: "none"
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    tapKwd: function(t) {
        this.setData({
            kwd: t.detail.value
        });
    },
    tapAddress: function(t) {
        this.setData({
            search_address: t.detail.value
        });
    },
    showAddress: function() {
        this.setData({
            showArea: !0
        });
    },
    onShowPopver: function() {
        var t = !this.data.showPopover;
        this.setData({
            showPopover: t
        });
    },
    onSelectPopver: function(t) {
        var e = t.currentTarget.dataset.item;
        this.setData({
            activeActions: e.text,
            activeActionsVaule: e.value,
            kwd: "",
            search_address: "",
            showPopover: !1
        }), this.getList();
    },
    confirmArea: function(t) {
        this.setData({
            positongStatus: 1,
            city: t.detail[1].name
        }), this.getList();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});